<?php

namespace app\admin\controller\haipi;

use app\common\controller\Backend;
use app\common\model\Area;

/**
 * 高端
 */
class Highend extends Backend
{
    /**
     * Highend模型对象
     * @var object
     * @phpstan-var \app\common\model\haipi\Highend
     */
    protected object $model;

    protected string|array $defaultSortField = 'weigh,desc';

    protected array|string $preExcludeFields = ['id', 'create_time', 'update_time'];

    protected string|array $quickSearchField = ['id'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new \app\common\model\haipi\Highend();
    }


    
    public function indexFilter($query){
        $search = $this->request->get('search/a');
        if($search){
            foreach($search  as  $value){
                if($value['field'] == 'areas_text'){
                        [$provinceCode, $cityCode] = Area::areaIdToCode($value['val']);
                        $query->where('city_code', $cityCode)
                        ->where('province_code', $provinceCode);
                }
            }
        }
        $query->append(['areas_text', 'is_home']);
    }

    public function readFilter($model){
        $model->append(['areas']);
    }
    /**
     * 若需重写查看、编辑、删除等方法，请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
     */
}